package com.c.ctgproject.adapter.guang

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.BatteryInWarehouseEntity
import com.c.ctgproject.entity.guang.BatteryInpuOtherEntity
import com.c.ctgproject.entity.guang.CarListEntity
import com.c.ctgproject.entity.guang.PowerBatteryOutEntity
import com.c.ctgproject.ui.collect.*
import com.c.ctgproject.utils.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.textColorResource

class BatteryInputConfirmAdapter(private val context: Context, private val mList: List<BatteryInpuOtherEntity.DataBean.ListBean>, private var hasBtn: Boolean = true,private val listener:BatteryInputConfirmCallback) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_battery_input_confirm_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mBottomRL.visibility = if (hasBtn) View.VISIBLE else View.GONE
            if (hasBtn) {
                when (data.status) {
                    0 -> {
                        holder.mBottomRL.visibility = View.VISIBLE
                        holder.mLine.visibility = View.VISIBLE

//                    holder.mStatueTV.text="待入库"
//                    holder.mStatueTV.textColorResource=R.color.red
                    }
                    1 -> {
                        holder.mBottomRL.visibility = View.GONE
                        holder.mLine.visibility = View.GONE
//                    holder.mStatueTV.text="已入库"
//                    holder.mStatueTV.textColorResource=R.color.colorAccent

                    }
                    else -> {
//                    holder.mStatueTV.text=""
                    }
                }
            }


            holder.batteryCode.text = data.batteryCode.noDataHandler()
            holder.mUserNameTV.text = data.createPersonName.noDataHandler()
//            holder.carPlate.text = data.carPlate.noDataHandler()
            holder.batterySelfCode.text = data.batterySelfCode.noDataHandler()
            holder.mTimeTV.text = data.createTime.noDataHandler()
            holder.mCodeTV.text = data.orderNo.noDataHandler()
            holder.mBatteryNameTV.text = data.batteryName.noDataHandler()
            val batteryType = when (data.batteryType) {
                1 -> "电池包"
                2 -> "模组"
                3 -> "电芯"
                else -> "暂无数据"
            }
            holder.mBatteryModelTV.text = batteryType
            holder.mBatteryCountTV.text = data.count.noDataHandler()
            holder.mBatteryFromTV.text = data.batterySource.noDataHandler()
//
//
            holder.mBottomRL.setOnClickListener {
                holder.mBTN.performClick()
            }
            holder.mBTN.setOnClickListener {
                //入库
                context.startActivity<BatteryInConfirmDetailActivity>(
                    MyConstants.POSITION to position,

                    MyConstants.ORDER_ID to data.orderId)

            }
            //详情
            holder.mParentLL.setOnClickListener {
                MyLog.d("目标值:${data.orderId}")
                if (data.orderId == null) {
                    context.showToast("该电池暂无详情")
                } else {
                    //入库单详情
                    context.startActivity<BatteryDetailActivity>(MyConstants.ORDER_ID to data.orderId)

                }

            }
            //holder.mDeleteBTN.visibility=if(data.isRemove==1)View.VISIBLE else View.GONE
            holder.mDeleteBTN.visibility=View.GONE
        }
    }
    interface BatteryInputConfirmCallback{
        fun itemDelete(position: Int,data:BatteryInpuOtherEntity.DataBean.ListBean)
    }
    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        //        val carPlate: TextView = view.findViewById(R.id.carPlate)
        val batteryCode: TextView = view.findViewById(R.id.batteryCode)
        val mCodeTV: TextView = view.findViewById(R.id.mCodeTV)
        val batterySelfCode: TextView = view.findViewById(R.id.batterySelfCode)
        val mLine: View = view.findViewById(R.id.mLine)
        val mUserNameTV: TextView = view.findViewById(R.id.mUserNameTV)

        //        val mStatueTV: TextView = view.findViewById(R.id.mStatueTV)
        val mTimeTV: TextView = view.findViewById(R.id.mTimeTV)
        val mBatteryNameTV: TextView = view.findViewById(R.id.mBatteryNameTV)
        val mBatteryModelTV: TextView = view.findViewById(R.id.mBatteryModelTV)
        val mBatteryCountTV: TextView = view.findViewById(R.id.mBatteryCountTV)
        val mBatteryFromTV: TextView = view.findViewById(R.id.mBatteryFromTV)
        val mBottomRL: RelativeLayout = view.findViewById(R.id.mBottomRL)
        val mBTN: Button = view.findViewById(R.id.mBTN)
        val mParentLL: LinearLayoutCompat = view.findViewById(R.id.mParentLL)
        val mDeleteBTN:Button=view.findViewById(R.id.mDeleteBTN)
    }


}